package com.geekteam.manga.Model;

import com.geekteam.manga.provider.MangaContract.RecentManga;

import android.content.ContentValues;
import android.database.Cursor;
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.BaseColumns;

public class RecentMangaModel extends BaseModel{
	
	private String mangaId;
	private long time;
	
	public RecentMangaModel(int _id, String mangaId, long time){
		super(_id);
		this.mangaId = mangaId;
		this.time = time;
	}

	public RecentMangaModel(Cursor cursor) {
		super(cursor);
		this._id = cursor.getInt(cursor.getColumnIndex(BaseColumns._ID));
		mangaId = cursor.getString(cursor.getColumnIndex(RecentManga.MANGA_ID));
		time = cursor.getLong(cursor.getColumnIndex(RecentManga.RECENTMANGA_TIME));
	}
	
	public ContentValues contentValues(long id){
		ContentValues values = new ContentValues();
		
		values.put(RecentManga.MANGA_ID, mangaId);
		values.put(RecentManga.RECENTMANGA_TIME, time);
		return values;
	}
	
	 static public String[] contentColumns (){
		return new String[] {RecentManga.MANGA_ID, 
				RecentManga.RECENTMANGA_TIME, RecentManga._ID};
	 }

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(_id);
		dest.writeString(mangaId);
		dest.writeLong(time);
	}
	
	public void readFromParcel(Parcel from){
		_id = from.readInt();
		mangaId  =from.readString();
		time = from.readLong();
	}
	
	
	public RecentMangaModel (Parcel parcel){
		super(parcel);
		readFromParcel(parcel);
		
	}
	
	@SuppressWarnings("rawtypes")
	public static final Parcelable.Creator CREATOR = new Parcelable.Creator<RecentMangaModel>() {

		@Override
		public RecentMangaModel createFromParcel(Parcel source) {
			return new RecentMangaModel(source);
		}

		@Override
		public RecentMangaModel[] newArray(int size) {
			return new RecentMangaModel[size];
		}
	};
	
	public void setMangaId(String mangaId){
		this.mangaId = mangaId;
	}
	
	public String getMangaId(){
		return mangaId;
	}
	
	public void setTime(long time){
		this.time = time;
	}
	
	public long getTime(){
		return time;
	}
	

}
